package com.arron.jvm.ref;

import java.lang.ref.WeakReference;

/**
 * @Classname WeakRefDemo
 * @Date 2020/8/23 23:50
 * @Created by 刘
 */
public class WeakRefDemo {

    //弱引用，不管内存是否充足，gc过程都要回收
    public static void main(String[] args) {

        Object o1 = new Object();
        WeakReference<Object> objectWeakReference = new WeakReference<>(o1);
        System.out.println("============gc之前=================");
        System.out.println(o1);
        System.out.println(objectWeakReference.get());

        o1=null;
        System.gc();

        System.out.println("===========gc之后=============");
        System.out.println(o1);
        System.out.println(objectWeakReference.get());


    }

}
